package ep1;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.Collections;


/**
 *
 * @author Elizabeth.Bourke
 */
public class BookStore {

   private  List<Book> booklist = new ArrayList<Book>();

    public BookStore() {
    }

    public void setUpData(){

         Book b1 = new Book("f","1238",20.99);
         Book b2 = new Book("e","1239",21.99);
         Book b3 = new Book("d","1236",22.99);
         Book b4 = new Book("c","1237",23.99);
         Book b5 = new Book("b","1234",24.99);
         Book b6 = new Book("a","1235",25.99);

         booklist.add(b1);
         booklist.add(b2);
         booklist.add(b3);
         booklist.add(b4);
         booklist.add(b5);
         booklist.add(b6);

    }

    public void printAllBooks(){

        Iterator<Book> i = booklist.iterator();
        while(i.hasNext()){
            i.next().print();
        }
    }

    public void sortByISBN(){

         Map<String,Book> myMap2 = new HashMap<String,Book>();

         for(Book i:booklist){
                 myMap2.put(i.getISBN(),i);
         }
         Set<String> ISBNkeys = myMap2.keySet();
         TreeSet<String> sortedISBNKeys = new TreeSet<String>(ISBNkeys);

         for(String i:sortedISBNKeys){
             Book a = myMap2.get(i);
             a.print();
         }
    }

    public void sortByTitle(){
        Collections.sort(booklist,new BookComparator());
        System.out.println("**Sorted list my title ***");
        printAllBooks();
         
    }
}
